package springboot.example.springboot.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import springboot.example.springboot.dao.UserInfoDao;
import springboot.example.springboot.entity.UserInfo;
import springboot.example.springboot.shiro.CryptographyUtil;
import springboot.example.springboot.tools.MyExecption;

import javax.annotation.Resource;

@Service
public class UserInfoService {

    @Resource
    private UserInfoDao infoDao;

    public UserInfo getByUserName(String userName) {
        return infoDao.getByUsername(userName);
    }

    public void save(UserInfo userInfo) throws MyExecption{
        if (StringUtils.isBlank(userInfo.getUsername())) {
            throw new MyExecption("用户名不能为空");
        }
        if (StringUtils.isBlank(userInfo.getPassword())) {
            throw new MyExecption("密码不能为空");
        }
        userInfo.setPassword(CryptographyUtil.md5(userInfo.getUsername(),userInfo.getPassword()));
        infoDao.save(userInfo);
    }
}
